import { body, param } from 'express-validator';
import { EvaluationStatus } from '../../types/evaluation';
import { validate } from '../validation';

export const evaluationValidator = {
  create: validate([
    body('userId')
      .isInt({ min: 1 })
      .withMessage('User ID must be a positive integer'),
    body('questionId')
      .isInt({ min: 1 })
      .withMessage('Question ID must be a positive integer'),
    body('score')
      .optional()
      .isInt({ min: 0, max: 100 })
      .withMessage('Score must be between 0 and 100'),
    body('feedback')
      .optional()
      .isString()
      .trim()
      .isLength({ min: 1, max: 1000 })
      .withMessage('Feedback must be between 1 and 1000 characters')
  ]),

  update: validate([
    param('id')
      .isInt({ min: 1 })
      .withMessage('Invalid evaluation ID'),
    body('score')
      .optional()
      .isInt({ min: 0, max: 100 })
      .withMessage('Score must be between 0 and 100'),
    body('feedback')
      .optional()
      .isString()
      .trim()
      .isLength({ min: 1, max: 1000 })
      .withMessage('Feedback must be between 1 and 1000 characters'),
    body('status')
      .optional()
      .isIn(Object.values(EvaluationStatus))
      .withMessage('Invalid evaluation status'),
    body('submittedAt')
      .optional()
      .isISO8601()
      .toDate()
      .withMessage('Invalid submission date')
  ]),

  getOne: validate([
    param('id')
      .isInt({ min: 1 })
      .withMessage('Invalid evaluation ID')
  ]),

  delete: validate([
    param('id')
      .isInt({ min: 1 })
      .withMessage('Invalid evaluation ID')
  ]),

  getByUser: validate([
    param('userId')
      .optional()
      .isInt({ min: 1 })
      .withMessage('Invalid user ID')
  ])
};
